﻿package lobby
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.display.Sprite;
	import lobby.events.LobbyEvent;
	import lobby.exchangeddata.HashTable;
	
	/**
	 * ...
	 * @author Nguyen Hoang Giang (Tom)
	 */
	public class HistoryPanelSicbo extends HistoryPanelBase
	{
		private static const SMALL:int = 10;
		private static const TRIPLE:int = 30;
		private static const MAX_NUM_CHECKERS:int = 66;
		
		public var textSmall:String = "S";
		public var textBig:String = "B";
		public var textTriple:String = "T";
		
		public override function initBoard(resultArr:Array):void
		{
			removeHistory();
			if (resultArr.length == 0)
				return;
			
			initText(GlobalVariables.langInfo.hashTable);
			
			var i:int;
			if (resultArr.length > MAX_NUM_CHECKERS)
			{
				i = Math.abs(resultArr.length - MAX_NUM_CHECKERS - rowNum - 1);
			}
			for (i; i < resultArr.length; i++)
			{
				var iconHis:MovieClip = attachIcon(resultArr[i].toString());
				iconHis.name = (i + 1).toString();
				if (rowInd + 1 == rowNum)
				{
					rowInd = 0;
					colInd++;
				}
				else
					rowInd++;
			}
		}
		
		public override function attachIcon(result:String):MovieClip
		{
			var hisIcon:MovieClip = MovieClip(new HistoryIconDc());
			var icon:MovieClip = hisIcon.mc;
			hisBoard.addChild(hisIcon);
			hisIcon.x = colInd * 18.5 + 9.25;
			hisIcon.y = rowInd * 18.5 + 9.25;
			//hisIcon.scaleX = hisIcon.scaleY = 0.69;
			icon.tf.mouseEnabled = false;
			
			var total:Number = Number(result);
			// small 
			if (total <= HistoryPanelSicbo.SMALL)
			{
				icon.gotoAndStop("small");
				icon.tf.text = textSmall;
				return hisIcon;
			}
			else
			{
				// triple
				if (total == HistoryPanelSicbo.TRIPLE)
				{
					icon.gotoAndStop("triple");
					icon.tf.text = textTriple;
					return hisIcon;
				}
				else // big
				{
					icon.gotoAndStop("big");
					icon.tf.text = textBig;
					return hisIcon;
				}
			}
			return null;
		}
		
		public function initText(hashTableInfo:HashTable):void
		{
			textTriple = hashTableInfo.lookupString("Triple");
			textSmall = hashTableInfo.lookupString("Small");
			textBig = hashTableInfo.lookupString("Big");
		}
	}

}